{"ast":null,"code":"import _classCallCheck from \"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/classCallCheck.js\";\nimport _createClass from \"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/createClass.js\";\n;\nexport var ParallelHasher = /*#__PURE__*/function () {\n  function ParallelHasher(workerUri, workerOptions) {\n    _classCallCheck(this, ParallelHasher);\n    this._queue = [];\n    this._ready = true;\n    var self = this;\n    if (Worker) {\n      self._hashWorker = new Worker(workerUri, workerOptions);\n      self._hashWorker.onmessage = self._recievedMessage.bind(self);\n      self._hashWorker.onerror = function (err) {\n        self._ready = false;\n        console.error('Hash worker failure', err);\n      };\n    } else {\n      self._ready = false;\n      console.error('Web Workers are not supported in this browser');\n    }\n  }\n  /**\n   * Hash a blob of data in the worker\n   * @param blob Data to hash\n   * @returns Promise of the Hashed result\n   */\n  _createClass(ParallelHasher, [{\n    key: \"hash\",\n    value: function hash(blob) {\n      var self = this;\n      var promise;\n      promise = new Promise(function (resolve, reject) {\n        self._queue.push({\n          blob: blob,\n          resolve: resolve,\n          reject: reject\n        });\n        self._processNext();\n      });\n      return promise;\n    }\n    /** Terminate any existing hash requests */\n  }, {\n    key: \"terminate\",\n    value: function terminate() {\n      this._ready = false;\n      this._hashWorker.terminate();\n    }\n    // Processes the next item in the queue\n  }, {\n    key: \"_processNext\",\n    value: function _processNext() {\n      if (this._ready && !this._processing && this._queue.length > 0) {\n        this._processing = this._queue.pop();\n        this._hashWorker.postMessage(this._processing.blob);\n      }\n    }\n    // Hash result is returned from the worker\n  }, {\n    key: \"_recievedMessage\",\n    value: function _recievedMessage(evt) {\n      var _a, _b;\n      var data = evt.data;\n      if (data.success) {\n        (_a = this._processing) === null || _a === void 0 ? void 0 : _a.resolve(data.result);\n      } else {\n        (_b = this._processing) === null || _b === void 0 ? void 0 : _b.reject(data.result);\n      }\n      this._processing = undefined;\n      this._processNext();\n    }\n  }]);\n  return ParallelHasher;\n}();","map":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IAAI,CAACJ,MAAM,CAACK,MAAM,GAAG,CAAC,EAAE;QAC5D,IAAI,CAACD,WAAW,GAAG,IAAI,CAACJ,MAAM,CAACM,GAAG,EAAE;QACpC,IAAI,CAACpB,WAAW,CAACqB,WAAW,CAAC,IAAI,CAACH,WAAY,CAACT,IAAI,CAAC;;IAE5D;IAEA;EAAA;IAAA;IAAA,OACQ,0BAAiBa,GAAQ;;MAC7B,IAAMC,IAAI,GAAGD,GAAG,CAACC,IAAI;MAErB,IAAIA,IAAI,CAACC,OAAO,EAAE;QACd,UAAI,CAACN,WAAW,0CAAEN,OAAO,CAACW,IAAI,CAACE,MAAM,CAAC;OACzC,MAAM;QACH,UAAI,CAACP,WAAW,0CAAEL,MAAM,CAACU,IAAI,CAACE,MAAM,CAAC;;MAGzC,IAAI,CAACP,WAAW,GAAGQ,SAAS;MAC5B,IAAI,CAACV,YAAY,EAAE;IACvB;EAAC;EAAA;AAAA","names":["ParallelHasher","workerUri","workerOptions","self","Worker","_hashWorker","onmessage","_recievedMessage","bind","onerror","err","_ready","console","error","blob","promise","Promise","resolve","reject","_queue","push","_processNext","terminate","_processing","length","pop","postMessage","evt","data","success","result","undefined"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/ts-md5/src/parallel_hasher.ts"],"sourcesContent":["export interface WorkerOptions {\n    credentials?: 'omit' | 'same-origin' | 'include';\n    name?: string;\n    type?: 'classic' | 'module';\n}\n\ndeclare var Worker: {\n    prototype: Worker;\n    new (stringUrl: string, options?: WorkerOptions): Worker;\n};\n\ninterface HashingRequest {\n    blob: any;\n    resolve: (...d: any) => void;\n    reject: (...d: any) => void;\n};\n\nexport class ParallelHasher {\n    private _queue: HashingRequest[] = [];\n    private _hashWorker: any;\n    private _processing?: HashingRequest;\n\n    private _ready: boolean = true;\n\n    constructor(workerUri: string, workerOptions?: WorkerOptions) {\n        const self = this;\n\n        if (Worker) {\n            self._hashWorker = new Worker(workerUri, workerOptions);\n            self._hashWorker.onmessage = self._recievedMessage.bind(self);\n            self._hashWorker.onerror = (err: any) => {\n                self._ready = false;\n                console.error('Hash worker failure', err);\n            };\n        } else {\n            self._ready = false;\n            console.error('Web Workers are not supported in this browser');\n        }\n    }\n\n    /**\n     * Hash a blob of data in the worker\n     * @param blob Data to hash\n     * @returns Promise of the Hashed result\n     */\n    public hash(blob: any) {\n        const self = this;\n        let promise;\n\n        promise = new Promise((resolve, reject) => {\n            self._queue.push({\n                blob,\n                resolve,\n                reject,\n            });\n\n            self._processNext();\n        });\n\n        return promise;\n    }\n\n    /** Terminate any existing hash requests */\n    public terminate() {\n        this._ready = false;\n        this._hashWorker.terminate();\n    }\n\n    // Processes the next item in the queue\n    private _processNext() {\n        if (this._ready && !this._processing && this._queue.length > 0) {\n            this._processing = this._queue.pop();\n            this._hashWorker.postMessage(this._processing!.blob);\n        }\n    }\n\n    // Hash result is returned from the worker\n    private _recievedMessage(evt: any) {\n        const data = evt.data;\n\n        if (data.success) {\n            this._processing?.resolve(data.result);\n        } else {\n            this._processing?.reject(data.result);\n        }\n\n        this._processing = undefined;\n        this._processNext();\n    }\n}\n"]},"metadata":{},"sourceType":"module"}